package com.ksm.web.controller.version;

import com.ksm.common.core.domain.AjaxResult;
import com.ksm.version.domain.SysVersionManage;
import com.ksm.version.domain.vo.ProjectVo;
import com.ksm.version.domain.vo.VersionVo;
import com.ksm.version.service.ProjectService;
import com.ksm.version.service.VersionService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DeployController {


    @Autowired
    private VersionService service;

    @Autowired
    private ProjectService projectService;

    /**
     * 通过应用名称和版本号查询是否要更新
     *
     * @param vo
     * @return
     */
    @PostMapping("/api/version/search")
    public AjaxResult search(@RequestBody VersionVo vo) {
        return AjaxResult.success(service.updateVersion(vo));
    }

    /**
     * 通过应用名称和版本号进行更新
     */
    @PostMapping("/api/version/windowsUpdateVersion")
    public AjaxResult platform(@RequestBody VersionVo vo) {

        return AjaxResult.success(service.windowsTriggerUpdateVersion(vo));
    }

    /**
     * 部署文件
     *
     * @param vo
     * @return
     */
    @PostMapping("/api/version/windowsClientAddVersion")
    public AjaxResult deploy(@RequestBody ProjectVo vo) {
        SysVersionManage manage = new SysVersionManage();
        manage.setDeployId(vo.getProjectDevelopmentId());
        if (projectService.findOne(manage).getRemoteDevelopment() == 1) {
            return AjaxResult.error("已部署");
        } else {
            return AjaxResult.success(service.windowsClientAdd(vo));
        }

    }

}
